package com.zhentao.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.comm.Result;
import com.zhentao.pojo.Schedule;
import com.zhentao.service.ScheduleService;
import com.zhentao.vo.ScheduleFormDTO;
import com.zhentao.vo.ScheduleQueryDTO;
import com.zhentao.vo.SourceFormDTO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Resource
    private ScheduleService scheduleService;

    // 分页查询排班列表
    @RequestMapping("/page")
    public Result<IPage<Schedule>> getSchedulePage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            ScheduleQueryDTO queryDTO
    ) {
        Page<Schedule> page = new Page<>(pageNum, pageSize);
        IPage<Schedule> result = scheduleService.getSchedulePage(page, queryDTO);
        return Result.success(result); // 统一返回结果
    }



    // 新增排班
    @RequestMapping("/save")
    public Result<Boolean> saveSchedule(@RequestBody ScheduleFormDTO formDTO) {
        boolean success = scheduleService.saveSchedule(formDTO);
        return success ? Result.success(true) : Result.error("新增失败");
    }

    // 编辑排班
    @RequestMapping("/update")
    public Result<Boolean> updateSchedule(@RequestBody ScheduleFormDTO formDTO) {
        boolean success = scheduleService.updateSchedule(formDTO);
        return success ? Result.success(true) : Result.error("编辑失败");
    }

    // 删除排班
    @RequestMapping("/del")
    public Result<Boolean> removeSchedule(Long scheduleId) {
        boolean success = scheduleService.removeSchedule(scheduleId);
        return success ? Result.success(true) : Result.error("删除失败");
    }

    // 调整号源
    @RequestMapping("/source/update")
    public Result<Boolean> updateSource(@RequestBody SourceFormDTO formDTO) {
        boolean success = scheduleService.updateSource(formDTO);
        return success ? Result.success(true) : Result.error("号源调整失败");
    }







}
